//
//  WmcBubbleContentView.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/5/12.
//

import UIKit

class WmcBubbleImageTextView: WmcImgTextControl {

    func setImageTextStyle(_ style: WmcBubbleVM.ContentStyle.ImageTextStyle, config: WmcBubbleVM.ContentStyle.ImageTextConfig) {
        switch style {
        case .imageTopTextBottom:
            imageView.snp.makeConstraints { make in
                if let imageSize = config.imageConfig.size {
                    make.top.centerX.equalToSuperview()
                    make.size.equalTo(imageSize)
                }else{
                    make.left.top.right.equalToSuperview()
                    make.height.equalToSuperview().multipliedBy(0.75)
                }
            }
            label.snp.makeConstraints { make in
                make.top.equalTo(imageView.snp.bottom).offset(config.imageTextSpacing)
                make.left.right.bottom.equalToSuperview()
            }
        case .imageLeftTextRight:
            imageView.snp.makeConstraints { make in
                if let imageSize = config.imageConfig.size {
                    make.left.centerY.equalToSuperview()
                    make.size.equalTo(imageSize)
                }else{
                    make.left.top.bottom.equalToSuperview()
                    make.width.equalToSuperview().multipliedBy(0.25)
                }
            }
            label.snp.makeConstraints { make in
                make.left.equalTo(imageView.snp.right).offset(config.imageTextSpacing)
                make.top.right.bottom.equalToSuperview()
            }
        case .imageBottomTextTop:
            imageView.snp.makeConstraints { make in
                if let imageSize = config.imageConfig.size {
                    make.bottom.centerX.equalToSuperview()
                    make.size.equalTo(imageSize)
                }else{
                    make.left.bottom.right.equalToSuperview()
                    make.height.equalToSuperview().multipliedBy(0.75)
                }
            }
            label.snp.makeConstraints { make in
                make.bottom.equalTo(imageView.snp.top).offset(config.imageTextSpacing)
                make.top.right.left.equalToSuperview()
            }
        case .imageRightTextLeft:
            imageView.snp.makeConstraints { make in
                if let imageSize = config.imageConfig.size {
                    make.right.centerY.equalToSuperview()
                    make.size.equalTo(imageSize)
                }else{
                    make.right.top.bottom.equalToSuperview()
                    make.width.equalToSuperview().multipliedBy(0.25)
                }
            }
            label.snp.makeConstraints { make in
                make.right.equalTo(imageView.snp.left).offset(config.imageTextSpacing)
                make.top.right.bottom.equalToSuperview()
            }
        }
        config.imageConfig.settingImageView(imageView)
//        if label.attributedText == nil {
            config.textConfig.settingLabel(label)
//        }
    }
}
